//
//  TaskViewController.m
//  StationManager
//
//  Created by 张佳强 on 17/3/10.
//  Copyright © 2017年 Helong. All rights reserved.
//

#import "TaskViewController.h"
#import "ListTableView.h"
#import "ValuePickerView.h"
#import "TaskCell.h"
#import "DataHandel.h"
#import "StationInfoModel.h"
#import "CommitTaskViewController.h"

@interface TaskViewController ()<UITableViewDelegate,UITableViewDataSource,AddSelectedDataDelegate>

//市Label
@property (nonatomic,strong) UILabel * city;
//背景View
@property (strong,nonatomic) UIView * bgView;
//县Label
@property (nonatomic,strong) UILabel * country;
//下划线Label
@property (nonatomic,strong) UILabel * baseLine;
//导航位置Label
@property (nonatomic,strong) UILabel * location;
//TableView数据源
@property (nonatomic,strong) NSMutableArray * dataArray;
//菜单数据数组Array
@property (nonatomic,strong) NSMutableArray * listArray;
//弹出提示
@property (strong,nonatomic) MBProgressHUD * hud;
//台站类型Label
@property (nonatomic,strong) UILabel * stationType;
//台站类型按钮Button
@property (nonatomic,strong) UIButton * typeButton;
//选择市按钮Button
@property (nonatomic,strong) UIButton * cityButton;
//下一步按钮Button
@property (nonatomic,strong) UIButton * nextButton;
//全选按钮Label
@property (nonatomic,strong) UILabel * buttonLabel;
//站名Label
@property (nonatomic,strong) UILabel * stationName;
//台站类型Label
@property (nonatomic,strong) UILabel * stationClass;
//全选按钮Button
@property (nonatomic,strong) UIButton * selectButton;
//站名／站号Label
@property (nonatomic,strong) UILabel * stationTitles;
//查询按钮Button
@property (nonatomic,strong) UIButton * searchButton;
//站号Label
@property (nonatomic,strong) UILabel * stationNumber;
//查询结果列表TableView
@property (nonatomic,strong) UITableView * tableView;
//选择县按钮Button
@property (nonatomic,strong) UIButton * countryButton;
//菜单列表TableView
@property (nonatomic,strong) ListTableView * listView;
//县选择器PickerView
@property (nonatomic,strong) ValuePickerView * pickView;
//选择的结果字典Dictionary
@property (nonatomic,strong) NSMutableDictionary * selectedDict;
//输入站名TextField
@property (nonatomic,strong) UITextField * stationTitleTextField;

@end

@implementation TaskViewController


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeButtonTitle:) name:@"changeButtonTitle" object:nil];
//    _selectButton.selected = NO;
//    [_tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"下达维护任务";
    _selectedDict = [[NSMutableDictionary alloc]initWithCapacity:0];
    [self setUI];        
}

//不用时移除通知
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"changeButtonTitle" object:nil];
}

#pragma mark Notification - Delegate

//更改按钮文字
- (void)changeButtonTitle:(NSNotification *)notify {
    
    NSDictionary * dict = (NSDictionary *)notify.object;
    if ([dict[@"buttonId"] integerValue] == 123) {
        [_typeButton setTitle:dict[@"data"] forState:UIControlStateNormal];
    }
    if ([dict[@"buttonId"] integerValue] == 456) {
        [_cityButton setTitle:dict[@"data"] forState:UIControlStateNormal];
    }
    if ([dict[@"buttonId"] integerValue] == 789) {
        [_countryButton setTitle:dict[@"data"] forState:UIControlStateNormal];
    }
    
    [_listView removeFromSuperview];
    _listView = nil;
    [_bgView removeFromSuperview];
    _bgView = nil;
}

//搭建页面UI
- (void)setUI {
    
    _nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _nextButton.frame = CGRectMake(0, 0, 45, 30);
    [_nextButton setTitle:@"下一步" forState:UIControlStateNormal];
    [_nextButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _nextButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
    [_nextButton addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_nextButton];
    
    _stationTitles = [[UILabel alloc] init];
    _stationTitles.backgroundColor = [UIColor clearColor];
    _stationTitles.text = @"站名/站号:";
    _stationTitles.font = [UIFont systemFontOfSize:13.0];
    _stationTitles.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_stationTitles];
    
    _stationType = [[UILabel alloc]init];
    _stationType.backgroundColor = [UIColor clearColor];
    _stationType.text = @"台站类型:";
    _stationType.font = [UIFont systemFontOfSize:13.0];
    _stationType.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_stationType];
    
    _city = [[UILabel alloc]init];
    _city.backgroundColor = [UIColor clearColor];
    _city.text = @"市:";
    _city.font = [UIFont systemFontOfSize:13.0];
    _city.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_city];
    
    _country = [[UILabel alloc]init];
    _country.backgroundColor = [UIColor clearColor];
    _country.text = @"县:";
    _country.font = [UIFont systemFontOfSize:13.0];
    _country.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_country];
    
    _stationTitleTextField = [[UITextField alloc]init];
    _stationTitleTextField.font = [UIFont systemFontOfSize:13.0];
    _stationTitleTextField.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_stationTitleTextField];
    
    _baseLine = [[UILabel alloc]init];
    _baseLine.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:_baseLine];
    
    _typeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_typeButton setTitle:@"全部" forState:UIControlStateNormal];
    [_typeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _typeButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    _typeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _typeButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    _typeButton.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    [_typeButton addTarget:self action:@selector(typeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_typeButton];
    
    UIImageView * arrowImageView1 = [[UIImageView alloc] init];
    arrowImageView1.image = [UIImage imageNamed:@"jiantou1"];
    [_typeButton addSubview:arrowImageView1];
    
    _cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_cityButton setTitle:@"全部" forState:UIControlStateNormal];
    _cityButton.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    [_cityButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _cityButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    _cityButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _cityButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [_cityButton addTarget:self action:@selector(cityClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_cityButton];
    
    UIImageView * arrowImageView2 = [[UIImageView alloc] init];
    arrowImageView2.image = [UIImage imageNamed:@"jiantou1"];
    [_cityButton addSubview:arrowImageView2];
    
    _countryButton = [UIButton buttonWithType:UIButtonTypeCustom];
    NSString *location = [USER_DEFAULT objectForKey:@"UserLocation"];

    if ([location isEqualToString:@"石家庄"]) {
        [_countryButton setTitle:@"全部" forState:UIControlStateNormal];
        
    }
    else{
        [_countryButton setTitle:location forState:UIControlStateNormal];
        
    }
    [_countryButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _countryButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    _countryButton.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    _countryButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _countryButton.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [_countryButton addTarget:self action:@selector(countryClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_countryButton];
    
    UIImageView * arrowImageView3 = [[UIImageView alloc] init];
    arrowImageView3.image = [UIImage imageNamed:@"jiantou1"];
    [_countryButton addSubview:arrowImageView3];
    
    _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _searchButton.backgroundColor = [UIColor colorWithRed:34/255.0 green:150/255.0 blue:243/255.0 alpha:1.0];
    _searchButton.layer.cornerRadius = 5;
    [_searchButton setTitle:@"查询" forState:UIControlStateNormal];
    [_searchButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _searchButton.titleLabel.font = [UIFont systemFontOfSize:13.0];
    [_searchButton addTarget:self action:@selector(searchClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_searchButton];
    
    _buttonLabel = [[UILabel alloc]init];
    _buttonLabel.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    [self.view addSubview:_buttonLabel];
    
    _selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_selectButton setImage:[UIImage imageNamed:@"unselected_bg"] forState:UIControlStateNormal];
    [_selectButton setImage:[UIImage imageNamed: @"selected_bg"] forState:UIControlStateSelected];
    [_selectButton addTarget:self action:@selector(selectClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_selectButton];
    
    _stationName = [[UILabel alloc]init];
    _stationName.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    _stationName.text = @"站名";
    _stationName.font = [UIFont systemFontOfSize:13.0];
    _stationName.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_stationName];
    
    _stationNumber = [[UILabel alloc]init];
    _stationNumber.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    _stationNumber.text = @"站号";
    _stationNumber.font = [UIFont systemFontOfSize:13.0];
    _stationNumber.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_stationNumber];
    
    _stationClass = [[UILabel alloc]init];
    _stationClass.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    _stationClass.text = @"站点类型";
    _stationClass.font = [UIFont systemFontOfSize:13.0];
    _stationClass.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_stationClass];
    
    _location = [[UILabel alloc]init];
    _location.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:244/255.0 alpha:1.0];
    _location.text = @"导航位置";
    _location.font = [UIFont systemFontOfSize:13.0];
    _location.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_location];
    
    _tableView = [[UITableView alloc]init];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_tableView];
    
    [_stationTitles mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@5);
        make.top.equalTo(@5);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    [_stationTitleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_stationTitles.mas_right).offset(5);
        make.top.equalTo(@5);
        make.right.equalTo(@-70);
        make.height.mas_equalTo(28);
    }];
    
    [_baseLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_stationTitles.mas_right).offset(5);
        make.top.equalTo(_stationTitleTextField.mas_bottom);
        make.right.equalTo(@-70);
        make.height.mas_equalTo(1);
    }];
    
    [_stationType mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@5);
        make.top.equalTo(_stationTitles.mas_bottom).offset(5);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    [_typeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_stationType.mas_right).offset(5);
        make.top.equalTo(_stationTitles.mas_bottom).offset(5);
        make.right.equalTo(@-70);
        make.height.mas_equalTo(30);
    }];
    
    [_city mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@5);
        make.top.equalTo(_stationType.mas_bottom).offset(5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
    
    [_cityButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_city.mas_right).offset(0);
        make.top.equalTo(_stationType.mas_bottom).offset(5);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
        
    }];
    
    [_country mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_cityButton.mas_right).offset(0);
        make.top.equalTo(_stationType.mas_bottom).offset(5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
    
    [_countryButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_country.mas_right).offset(0);
        make.top.equalTo(_stationType.mas_bottom).offset(5);
        make.right.equalTo(@-70);
        make.height.mas_equalTo(30);
    }];
    
    [_searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_typeButton);
        make.right.equalTo(@-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(30);
    }];
    
    [_buttonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@1);
        make.top.equalTo(_city.mas_bottom).offset(10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
        
    }];
    
    [_selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@1);
        make.top.equalTo(_city.mas_bottom).offset(10);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(30);
    }];
    
    [_stationName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_buttonLabel.mas_right).offset(1);
        make.top.equalTo(_city.mas_bottom).offset(10);
        make.width.mas_equalTo((SCREEN_WIDTH-36)/4);
        make.height.mas_equalTo(30);
    }];
    
    [_stationNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_stationName.mas_right).offset(1);
        make.top.equalTo(_city.mas_bottom).offset(10);
        make.width.mas_equalTo((SCREEN_WIDTH-36)/4);
        make.height.mas_equalTo(30);
        
    }];
    
    [_stationClass mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_stationNumber.mas_right).offset(1);
        make.top.equalTo(_city.mas_bottom).offset(10);
        make.width.mas_equalTo((SCREEN_WIDTH-36)/4);
        make.height.mas_equalTo(30);
        
    }];
    
    [_location mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_stationClass.mas_right).offset(1);
        make.top.equalTo(_city.mas_bottom).offset(10);
        make.width.mas_equalTo((SCREEN_WIDTH-36)/4);
        make.height.mas_equalTo(30);
        
    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.top.equalTo(_stationName.mas_bottom);
        make.width.mas_equalTo(SCREEN_WIDTH);
        make.bottom.equalTo(@0);
    }];
    
    [arrowImageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(0);
        make.top.equalTo(@5);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    [arrowImageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(0);
        make.top.equalTo(@5);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    [arrowImageView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(0);
        make.top.equalTo(@5);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
}

//移除菜单
- (void)hide {
    
    [_listView removeFromSuperview];
    _listView = nil;
    [self.bgView removeFromSuperview];
    self.bgView = nil;
}

//解析本地json数据
- (NSDictionary *)jsonDict {
    
    NSString * filePath = [[NSBundle mainBundle] pathForResource:@"Maintenance" ofType:@"json"];
    NSData * jsonData = [[NSData alloc]initWithContentsOfFile:filePath];
    id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:nil];
    NSDictionary * dict = jsonObject[@"task"];
    return dict;
}

//点击台站类型
- (void)typeClick {
    
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.bgView.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
    [self.bgView addGestureRecognizer:tap];
    [self.view addSubview:self.bgView];
    
    NSDictionary * dict = [self jsonDict];
    _listArray = dict[@"list"][@"type"];
    _listView = [[ListTableView alloc]initWithFrame:CGRectMake(_typeButton.frame.origin.x, _typeButton.frame.origin.y+30, SCREEN_WIDTH-160, _listArray.count*40) style:UITableViewStylePlain];
    _listView.vcName = @"Task";
    _listView.buttonId = 123;
    _listView.dataArray = _listArray;
    [_listView reloadData];
    [self.view addSubview:_listView];
    
}

//点击市
- (void)cityClick {
    
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.bgView.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
    [self.bgView addGestureRecognizer:tap];
    [self.view addSubview:self.bgView];
    
    NSDictionary * dict = [self jsonDict];
    _listArray = dict[@"list"][@"city"];
    _listView = [[ListTableView alloc]initWithFrame:CGRectMake(45, _cityButton.frame.origin.y+30, 80, _listArray.count*40) style:UITableViewStylePlain];
    _listView.vcName = @"Task";
    _listView.dataArray = _listArray;
    _listView.buttonId = 456;
    [_listView reloadData];
    [self.view addSubview:_listView];
}

//点击县
- (void)countryClick {
    
    [_listArray removeAllObjects];
    _listArray = [NSMutableArray arrayWithCapacity:0];
    NSDictionary * dict = [self jsonDict];
    NSString *location = [USER_DEFAULT objectForKey:@"UserLocation"];
    
    if ([location isEqualToString:@"石家庄"]) {
       _listArray = dict[@"list"][@"country"];
        
    }
    else{
       NSArray *array = dict[@"list"][@"country"];
        for (NSString *name in array) {
            
            if ([name containsString:location]) {
                
                [_listArray addObject:name];
            }
        }
        
    }
    
    _pickView = [[ValuePickerView alloc]init];
    _pickView.dataSource =_listArray;
    _pickView.pickerTitle = @"县";
    __weak typeof(self) weakSelf = self;
    _pickView.valueDidSelect = ^(NSString *value){
        NSArray * stateArr = [value componentsSeparatedByString:@"/"];
        [weakSelf.countryButton setTitle:stateArr[0] forState:UIControlStateNormal];
    };
    [_pickView show];
}

//点击查询
- (void)searchClick {
    [_selectedDict removeAllObjects];
    [_dataArray removeAllObjects];
    _dataArray = [NSMutableArray arrayWithCapacity:0];
    NSArray * paramsarray = @[_stationTitleTextField.text,_typeButton.titleLabel.text,_cityButton.titleLabel.text,_countryButton.titleLabel.text];
    [[DataHandel sharedDataHandel] getTaskStationWith:paramsarray success:^(id responseObject) {
        _dataArray = responseObject;
        _selectButton.selected = NO;
        [_tableView reloadData];
    }];
}

//点击下一步
- (void)nextClick {
    
//    NSLog(@"dictcount:%zi",_selectedDict.count);
    if (_selectedDict.count>0) {
        CommitTaskViewController * commit = [[CommitTaskViewController alloc]init];
        commit.selectedDict = _selectedDict;
        [self.navigationController pushViewController:commit animated:YES];
    }else{
        [self showAlert:@"请选择台站" duration:0.8];
    }
}

//弹出提示框
- (void)showAlert:(NSString *)message duration:(CGFloat)duration {
    
    _hud = [[MBProgressHUD alloc] init];
    _hud.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2);
    [self.view addSubview:_hud];
    _hud.animationType =MBProgressHUDAnimationZoom;
    _hud.mode = MBProgressHUDModeText;
    _hud.label.text = message;
    _hud.removeFromSuperViewOnHide = YES;
    [_hud showAnimated:NO];
    [_hud hideAnimated:YES afterDelay:duration];
    
}

//点击全选
- (void)selectClick {
    

    
    
    if (_selectButton.selected) {
        _selectButton.selected = NO;
        
       
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"unselected" object:nil];
        for (StationInfoModel *model in _dataArray) {
            model.isSelected = NO;
        }
        [_selectedDict removeAllObjects];
        [_tableView reloadData];
    }else{
        _selectButton.selected = YES;
        
        for (int i = 0; i< _dataArray.count; i++) {
            
            StationInfoModel *model = _dataArray[i];
            model.isSelected = YES;
            [_selectedDict setValue:model forKey:[NSString stringWithFormat:@"%i",i]];
            
        }
       //        [[NSNotificationCenter defaultCenter] postNotificationName:@"selected" object:nil];
        
        [_tableView reloadData];
    }
}

#pragma mark 自定义Delegate

//添加选中的台站信息
- (void)addSelectedCell:(NSInteger)celltag {
    
    
    StationInfoModel *model = _dataArray[celltag];
    model.isSelected = YES;
    [_selectedDict setValue:model forKey:[NSString stringWithFormat:@"%i",celltag]];
    
}

//删除选中的台站信息
- (void)deleteSelectedCell:(NSInteger)celltag {
    StationInfoModel *model = _dataArray[celltag];
    model.isSelected = NO;
    [_selectedDict removeObjectForKey:[NSString stringWithFormat:@"%i",celltag]];
}

#pragma mark TableView - Delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString * iden = @"iden";
    TaskCell * cell = [tableView dequeueReusableCellWithIdentifier:iden];
    if (cell == nil) {
        cell = [[TaskCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
    }
    StationInfoModel * model = _dataArray[indexPath.row];
    cell.stationName.text = model.stationName;
    cell.stationNumber.text = model.stationNum;
    cell.stationType.text = model.stationType;
    cell.location.text = model.navigationPosition;
    cell.cellTag = indexPath.row;
    cell.addSelectedDelegate = self;
    
    if (model.isSelected) {
        
        cell.selectButton.selected = YES;
    }
    else{
        cell.selectButton.selected = NO;
    }
//    if (_selectButton.selected == YES) {
//        cell.selectButton.selected = YES;
//        [_selectedDict setValue:_dataArray[indexPath.row] forKey:[NSString stringWithFormat:@"%i",indexPath.row]];
//        
//    }else{
//        cell.selectButton.selected = NO;
//        [_selectedDict removeObjectForKey:[NSString stringWithFormat:@"%i",indexPath.row]];
//    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 30;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
